package com.zline.foodraise.view;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.zline.foodraise.R;
import com.zline.foodraise.constant.Constant;
import com.zline.foodraise.entity.CommentBean;
import com.zline.foodraise.entity.CustomerUserBean;
import com.zline.foodraise.listener.RecyclerItemClicked;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by heshantao on 15/7/6.
 * 评论列表
 */
@EViewGroup(R.layout.dynamic_item_comment_item)
public class DynamicItemCommentItem extends RelativeLayout {
    private static final String LOG_TAG = DynamicItemCommentItem.class.getSimpleName();
    RecyclerItemClicked itemClicked;
    int position;
    int parentPosition;
    @ViewById(R.id.dynamic_item_support_item_circleIv)
    CircleImageView iv;
    @ViewById(R.id.dynamic_item_support_item_vip)
    ImageView vip_iv;
    @ViewById(R.id.dynamic_item_comment_item_tv)
    TextView tv;
    ImageLoader imageLoader;
    String picUrl;
    int authenticateType;

    public DynamicItemCommentItem(Context context) {
        super(context);
    }

    public void bind(CommentBean commentBean, int position, int parentPosition,DisplayImageOptions options) {
        this.position = position;
        this.parentPosition = parentPosition;
        imageLoader = ImageLoader.getInstance();
        CustomerUserBean userBean = commentBean.getUserBean();
        if (userBean != null) {
            picUrl = userBean.getAvatarPicUrl();
            imageLoader.displayImage(picUrl, iv, options);
            authenticateType = userBean.getIdentificateType();
            if (authenticateType == 1) {
                vip_iv.setVisibility(View.VISIBLE);
            } else {
                vip_iv.setVisibility(View.GONE);
            }
        }
        String content = commentBean.getContent();
        tv.setText(content);
    }

    @Click(R.id.dynamic_item_comment_item_rl)
    void onClick() {
        if (parentPosition < 0) {
            itemClicked.onRecyclerItemClicked(Constant.DYNAMIC_COMMENT_FLAG, position);
        } else {
            itemClicked.onRecyclerItemClicked(Constant.DYNAMIC_COMMENT_FLAG, parentPosition);
        }
    }

    public void setRecyclerItemClick(RecyclerItemClicked clicked) {
        this.itemClicked = clicked;

    }
}
